package com.be.beadmin.service.controller;

import com.be.beadmin.common.entity.PageEntity;
import com.be.beadmin.common.exception.BeadminException;
import com.be.beadmin.common.utils.ResultModel;
import com.be.beadmin.service.dto.input.DictTypeDto;
import com.be.beadmin.service.service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
* @author zjm
* @date 2023-02-02
**/
@RestController
public class DictTypeController {

    @Autowired
    private  DictTypeService dictTypeService;


    @PostMapping(value = "/service/getDictTypeByPage")
    public ResultModel getDictTypeByPage(@RequestBody PageEntity pageEntity)  {
        return ResultModel.success(dictTypeService.getDictTypeByPage(pageEntity)) ;
    }

    @PostMapping("/service/addDictType")
    public ResultModel addDictType(@RequestBody DictTypeDto dictTypeDto){
        try {
            dictTypeService.addDictType(dictTypeDto);
            return ResultModel.success(ResultModel.ADD);

        } catch (BeadminException e) {
            return ResultModel.error(-1,e.getMessage());
        } catch (Exception e){
            return ResultModel.error(-2,e.getMessage());
        }
    }

    @PostMapping("/service/delDictType")
    public ResultModel delDictType(@RequestBody DictTypeDto dictTypeDto){
        dictTypeService.delDictType(dictTypeDto.getId());
        return ResultModel.success(ResultModel.DELETE);
    }


    @PostMapping("/service/updateDictType")
    public ResultModel updateDictType(@RequestBody DictTypeDto dictTypeDto){
        dictTypeService.updateDictType(dictTypeDto);
        return ResultModel.success(ResultModel.UPDATE);
    }
}